$(function(){
	var admin_id = getCookie('admin_id');
	if(!admin_id){
		window.location.replace('login.html');
	}
	$.ajax({
		url: ApiUrl + "/admin?limit="+Page,
        type: 'get',
        dataType: 'JSON',
        success: function(result) {
        	if(result.code == 200){
        		var pageCount = result.data.totalPage;
        		//生成分页按钮
				if(pageCount>5){
					page_icon(1,5,0,pageCount);
				}else{
					page_icon(1,pageCount,0,pageCount);
				}
        	}else{
	    		parent.layer.msg(result.message);
	    		return false;
	    	}
        }
    });
	list_value();
});
function list_value(page){
	if(!page){
		//获取店员列表
	    $.ajax({
			url: ApiUrl + "/admin?limit="+Page,
	        type: 'get',
	        dataType: 'JSON',
	        success: function(result) {
	        	if(result.code == 200){
	        		var html='';
	        		$.each(result.data.list, function(k, v) {
	        			html+='<tr>'
	                            +'<td>'+v.uid+'</td>'
	                            +'<td>'+v.real_name+'</td>'
	                            +'<td>'+v.phone+'</td>'
	                            +'<td>'+v.status+'</td>'
	                            +'<td>'+v.created_at+'</td>'
	                            +'<td><a title = "编辑店员"  href="admin_edit.html?id='+v.id+'" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>'
	                            +'    <a title = "修改密码"  href="admin_password.html?id='+v.id+'" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>'
	                            +'    <a title = "重置密码"  onclick="reset('+v.id+')" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>'
	                            +'</td>'
	                        + '</tr>';
	        		});
	        		$("#value").html(html);
	        	}else{
		    		parent.layer.msg(result.message);
		    		return false;
		    	}
	        }
	    });
	}else{
		//$("#value").empty();
		//获取店员列表
	    $.ajax({
			url: ApiUrl + "/admin?limit="+Page+"&page="+page,
	        type: 'get',
	        dataType: 'JSON',
	        success: function(result) {
	        	if(result.code == 200){
	        		var html='';
	        		$.each(result.data.list, function(k, v) {
	        			html+='<tr>'
	                            +'<td>'+v.uid+'</td>'
	                            +'<td>'+v.real_name+'</td>'
	                            +'<td>'+v.phone+'</td>'
	                            +'<td>'+v.status+'</td>'
	                            +'<td>'+v.created_at+'</td>'
	                            +'<td><a title = "编辑店员"  href="admin_edit.html?id='+v.id+'" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>'
	                            +'    <a title = "修改密码"  href="admin_password.html?id='+v.id+'" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>'
	                            +'    <a title = "重置密码"  onclick="reset('+v.id+')" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>'
	                            +'</td>'
	                        + '</tr>';
	        		});
	        		$("#value").html(html);
	        	}else{
		    		parent.layer.msg(result.message);
		    		return false;
		    	}
	        }
	    });
	}
	
}
//重置密码
function reset(id){
	 $.ajax({
			url: ApiUrl + "/admin/reset/"+id,
	        type: 'get',
	        dataType: 'JSON',
	        success: function(result) {
	        	if(result.code == 200){
	        		if(result.data){
	        			parent.layer.msg("重置密码成功！");
	    				return false;
	        		}else{
	        			parent.layer.msg("重置密码失败！");
		    			return false;
	        		}
	        	}
        	}
   });
}
